package com.qf.contract.controller;

import com.qf.common.base.exception.ControllerException;
import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.contract.qo.FContractPaymentQo;
import com.qf.contract.service.FContractPaymentSerivce;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

@Api(tags = "支付子模块")
@RestController
@RequestMapping("/fcontractpaymentcontroller")
public class FContractPaymentController {
    @Resource
    private FContractPaymentSerivce fContractPaymentSerivce;

    @ApiOperation("添加支付记录")
    @PutMapping("/addfcontractpayment")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult addFContractPayment(FContractPaymentQo fContractPaymentQo) {
        try {
            return RespResult.success(fContractPaymentSerivce.addFContractPayment(fContractPaymentQo));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("批量删除支付记录")
    @DeleteMapping("/delcontractpayment")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult delContractPayment(Integer[] ids) {
        try {
            return RespResult.success(fContractPaymentSerivce.delContractPayment(Arrays.asList(ids)));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("分页查询支付信息")
    @GetMapping("/fcontractpaymentserivce")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult fContractPaymentSerivce(FContractPaymentQo fContractPaymentQo, @RequestParam(defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size) {
        try {
            return RespResult.success(fContractPaymentSerivce.fContractPaymentSerivce(fContractPaymentQo, current, size));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }
}
